package com.ruoyi.app.controller;

import com.ruoyi.app.domain.OrderInfo;
import com.ruoyi.app.domain.vo.OrderInfoVo;
import com.ruoyi.app.service.IOrderInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

/**
 * 订单详情Controller
 * 
 * @author zhangkaiqiang
 * @date 2024-10-20
 */
@RestController
@RequestMapping("/order/orderInfo")
public class OrderInfoController extends BaseController
{
    @Autowired
    private IOrderInfoService orderInfoService;

    /**
     * 查询订单详情列表
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:list')")
    @GetMapping("/list")
    public AjaxResult list(OrderInfoVo orderInfo)
    {
        startPage();
        orderInfo.setShopId(getShopId());
        List<OrderInfoVo> list = orderInfoService.selectOrderInfoList(orderInfo);
        return success(getDataTable(list));
    }

    /**
     * 导出订单详情列表
     */
    @PreAuthorize("@ss.hasPermi('order:orderInfo:export')")
    @Log(title = "订单详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OrderInfoVo orderInfoVo)
    {
        List<OrderInfoVo> list = orderInfoService.selectOrderInfoList(orderInfoVo);
        ExcelUtil<OrderInfoVo> util = new ExcelUtil<OrderInfoVo>(OrderInfoVo.class);
        util.exportExcel(response, list, "订单详情数据");
    }

    /**
     * 获取订单详情详细信息
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(orderInfoService.selectOrderInfoById(id));
    }

    /**
     * 新增订单详情
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:add')")
    @Log(title = "订单详情", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    public AjaxResult add(@RequestBody OrderInfoVo orderInfoVo)
    {
        orderInfoVo.setSalesmanId(getUserId());
        orderInfoVo.setSalesmanName(getUsername());
        orderInfoVo.setShopId(getShopId());
        return success().setData(orderInfoService.add(orderInfoVo));
    }

    /**
     * 修改订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:orderInfo:edit')")
    @Log(title = "订单详情", businessType = BusinessType.UPDATE)
    @PutMapping("/edit")
    public AjaxResult edit(@RequestBody OrderInfo orderInfo)
    {
        return toAjax(orderInfoService.updateById(orderInfo));
    }

    /**
     * 删除订单详情
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:remove')")
    @Log(title = "订单详情", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        List<String> objects = Arrays.asList(ids);
        return toAjax(orderInfoService.removeByIds(objects));
    }

    /**
     * 新增订单详情
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:save')")
//    @Log(title = "订单详情", businessType = BusinessType.INSERT)
//    @PostMapping("/save")
//    public AjaxResult save(@RequestBody OrderInfoVo orderInfoVo)
//    {
//        return toAjax(orderInfoService.save(orderInfoVo));
//    }


    /**
     * 统计分析
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:list')")
    @GetMapping("/statistics")
    public AjaxResult statistics(OrderInfoVo orderInfoVo)
    {
        orderInfoVo.setShopId(getShopId());
        List<OrderInfoVo> list = orderInfoService.statistics(orderInfoVo);
        return success(getDataTable(list));
    }

    /**
     * 统计分析 订单详情
     */
//    @PreAuthorize("@ss.hasPermi('order:orderInfo:list')")
    @GetMapping("/statisticsInfo")
    public AjaxResult statisticsInfo(OrderInfoVo orderInfoVo)
    {
        orderInfoVo.setShopId(getShopId());
        OrderInfoVo infoVo = orderInfoService.statisticsInfo(orderInfoVo);
        return success(infoVo);
    }


}
